#include <stdlib.h>
#include <stdio.h>
#include <math.h>
#include <time.h>
#include <omp.h>

#define REPEAT 256


__inline__ float f(float x,float y){
  return sinf(cosf(sinf(sqrtf(powf(cosf(x*x+y*y),1.5f)))));
}


int main(void){
  long unsigned int N = 1024L*1024*256;
  float *a = (float *)malloc(N*sizeof(float));
  float *b = (float *)malloc(N*sizeof(float));
  struct timespec ts0,ts1;
  double time;  
  
  fprintf(stderr,"*** HOST ***\n\nFilling arrays\n");
  for (long unsigned int i=0;i<N;i++){
    a[i] = (float)rand()/(float)(RAND_MAX);
    b[i] = (float)rand()/(float)(RAND_MAX);
  }
  
  clock_gettime(CLOCK_REALTIME,&ts0);
  fprintf(stderr,"Processing arrays");

  
  for (int count=0;count<REPEAT;count++) {
#pragma omp parallel for num_threads(6)
    for (long unsigned int i=0;i<N;i++) a[i] = f(a[i], b[i]);
  }

  
  clock_gettime(CLOCK_REALTIME,&ts1);
  time = (ts1.tv_sec-ts0.tv_sec + (ts1.tv_nsec-ts0.tv_nsec)/1e9);
  fprintf(stderr," : %.2f seconds\n\n\n",time);
  exit(0);
}
